// ignore_for_file: prefer_const_constructors

import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:get/get.dart';

/// 支付成功页面
class PaymentSuccessPage extends StatefulWidget {
  const PaymentSuccessPage({Key? key}) : super(key: key);

  @override
  _PaymentSuccessPageState createState() => _PaymentSuccessPageState();
}

class _PaymentSuccessPageState extends State<PaymentSuccessPage> {
  @override
  Widget build(BuildContext context) {
    // 获取参数
    final args = Get.arguments ?? {};
    debugPrint("args ${jsonEncode(args)}");
    final String orderNo = args["orderNo"] ?? "";
    final double amount = args["amount"] ?? 0;
    return Scaffold(
      appBar: AppBar(title: Text('支付成功'), automaticallyImplyLeading: false),
      body: Center(
        child: Padding(
          padding: const EdgeInsets.symmetric(horizontal: 32.0),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              Icon(Icons.check_circle_outline, color: Colors.green, size: 100),
              SizedBox(height: 16),
              Text(
                '支付成功',
                style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
              ),
              SizedBox(height: 8),
              Text(
                '订单号：${orderNo}',
                style: TextStyle(fontSize: 16, color: Colors.grey[600]),
              ),
              SizedBox(height: 4),
              Text(
                '金额：¥${amount.toStringAsFixed(2)}',
                style: TextStyle(fontSize: 16, color: Colors.grey[600]),
              ),
              SizedBox(height: 32),
              ElevatedButton(
                onPressed: () {
                  // 查看订单详情
                  Get.toNamed('/order_detail', arguments: {'orderNo': orderNo});
                },
                child: Text('查看订单'),
                style: ElevatedButton.styleFrom(
                  minimumSize: Size(double.infinity, 48),
                ),
              ),
              SizedBox(height: 12),
              OutlinedButton(
                onPressed: () {
                  // 返回首页
                  Get.offAllNamed('/');
                },
                child: Text('返回首页'),
                style: OutlinedButton.styleFrom(
                  minimumSize: Size(double.infinity, 48),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
